<%-- 
    Document   : editAttributes
    Created on : 1.6.2012, 21:42:18
    Author     : tuhar
--%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Edit Invoice</title>
        <link rel="stylesheet" href="<c:url value="/default.css"/>" type="text/css">
        <script type="text/javascript">
                var i = 0;
                window.onload=function(){
                    var table = document.getElementById("items");
                    var lastTr = table.getElementsByTagName("tr").length;                    
                    i=lastTr+1;
                }
            function addRow(){
                var table = document.getElementById("items");
                var row = document.createElement("tr");
                var name = document.createElement("th");
                var price = document.createElement("th");
                var amount = document.createElement("th");
                var nameData = document.createElement("td");
                var priceData = document.createElement("td");
                var amountData = document.createElement("td");
                var nameInput = document.createElement("input");
                var priceInput = document.createElement("input");
                var amountInput = document.createElement("input");
                name.appendChild(document.createTextNode("Názov*"));
                price.appendChild(document.createTextNode("Cena*"));
                amount.appendChild(document.createTextNode("Počet*"));
                row.name="row"+i;
                nameInput.type="text";
                nameInput.name="itemName"+i;
                nameInput.setAttribute("required", "required");
                nameInput.setAttribute("title", "název zboží")
                priceInput.type="text";
                priceInput.name="itemPrice"+i;
                priceInput.setAttribute("required", "required");
                priceInput.setAttribute("pattern", "[0-9]+|[0-9]+\.[0-9]+");
                priceInput.setAttribute("title","např.: 1.0");
                amountInput.type="text";
                amountInput.name="itemAmount"+i;
                amountInput.setAttribute("required", "required");
                amountInput.setAttribute("pattern", "[1-9][0-9]*");
                amountInput.setAttribute("title", "Množství zboží")
                nameData.appendChild(nameInput);
                priceData.appendChild(priceInput);
                amountData.appendChild(amountInput);
                row.appendChild(name);
                row.appendChild(nameData);
                row.appendChild(price);
                row.appendChild(priceData);
                row.appendChild(amount);
                row.appendChild(amountData);
                table.appendChild(row);
                i++;
            }
        </script>
    </head>
    <body>
        <div>
        <h1>Upraviť faktúru</h1>
        <form action="<c:url value="/EditAttributesInvoice?id=${invoice.id}"/>"  method="post">
            <table style="margin:0px auto">
                <tr>
                    <th>Číslo faktúry*:</th>
                    <td><input type="text" name="invNum" value="${invoice.invoiceNumber}" required="required" pattern="[0-9]+" title="číslo faktury" /></td>
                </tr>
                <tr>
                    <th>Typ platby*:</th>
                    <td><select name="paymentType">
                            <option value="cash">hotovosť</option>
                            <option value="creditCard">kreditná karta</option>
                            <option value="transaction">prevod na účet</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <th>Dátum vystavenia*:</th>
                    <td><input type="text" name="invoicingDate" value="${niceInvoicingDate}" pattern="[0-9]{2}/[0-9]{2}/[0-9]{4}" title="dd/mm/rrrr" required="required" />
                    </td>
                </tr>
                <tr>
                    <th>Dátum splatnosti*:</th>
                    <td><input type="text" name="dueDate" value="${niceDueDate}" pattern="[0-9]{2}/[0-9]{2}/[0-9]{4}" title="dd/mm/rrrr" required="required" />
                    </td>
                </tr>
                <tr>
                    <th>Účet:</th>
                    <td><input type="text" name="bankAccount" value="${invoice.bankAccount}" pattern="[[1-9][0-9]{8}/[0-9]{4}]?" title="bankovní účet např.: 123456789/1234" />
                    </td>
                </tr>
                <tr>
                    <th>Faktúru vystavil*:</th>
                    <td><input type="text" name="drawer" value="${invoice.drawer}" required="required" title="jméno vystavitele" />
                    </td>
                </tr>
                <tr>
                    <th>Variabilný symbol:</th>
                    <td><input type="text" name="variableSymbol" value="${invoice.variableSymbol}" pattern="[0-9]{0,9}" title="číslo v rozsahu 0-999999999" />
                    </td>
                </tr>
            </table>
            Dodávateľ:
            <table style="margin:0px auto">
                <tr>
                    <th>Meno*:</th>
                    <td><input type="text" name="disName" value="${invoice.distributor.subjectName}" required="required" title="jméno dodavatele"/></td>
                </tr>
                <tr>
                    <th>Mesto*:</th>
                    <td><input type="text" name="disCity" value="${invoice.distributor.city}" required="required" title="město" /></td>
                </tr>
                <tr>
                    <th>Ulica:</th>
                    <td><input type="text" name="disStreet" value="${invoice.distributor.street}" title="ulice" /></td>
                </tr>
                <tr>
                    <th>Číslo ulice*:</th>
                    <td><input type="text" name="disStreetNum" value="${invoice.distributor.number}" required="required" pattern="[0-9]+" title="číslo popisné" /></td>
                </tr>
                <tr>
                    <th>PSČ*:</th>
                    <td><input type="text" name="disPostalCode" value="${invoice.distributor.postalCode}" required="required" pattern="[1-8][0-9]{4}" title="10000 - 80000" /></td>
                </tr>
                <tr>
                    <th>Telefón:</th>
                    <td><input type="text" name="disPhone" value="${invoice.distributor.phone}" pattern="[[\+][1-9][0-9]{11}]?" title="telefon např.: +420123456789" /></td>
                </tr>
                <tr>
                    <th>E-mail:</th>
                    <td><input type="email" name="disMail" value="${invoice.distributor.mail}" /></td>
                </tr>
                <tr>
                    <th>IČO:</th>
                    <td><input type="text" name="disICO" value="${invoice.distributor.idNumber}" pattern="[[1-9][0-9]{7}]?" title="IČO v rozsahu 10000000 - 99999999" /></td>
                         </tr>
            </table>
            Odberateľ:
            <table style="margin:0px auto">
                <tr>
                    <th>Meno*:</th>
                    <td><input type="text" name="conName" value="${invoice.consumer.subjectName}" required="required" title="jméno odběratele" /></td>
                </tr>
                <tr>
                    <th>Mesto*:</th>
                    <td><input type="text" name="conCity" value="${invoice.consumer.city}" required="required" title="město" /></td>
                </tr>
                <tr>
                    <th>Ulica:</th>
                    <td><input type="text" name="conStreet" value="${invoice.consumer.street}" title="ulice" /></td>
                </tr>
                <tr>
                    <th>Číslo ulice*:</th>
                    <td><input type="text" name="conStreetNum" value="${invoice.consumer.number}" required="required" pattern="[0-9]+" title="číslo popisné" /></td>
                </tr>
                <tr>
                    <th>PSČ*:</th>
                    <td><input type="text" name="conPostalCode" value="${invoice.consumer.postalCode}" required="required" pattern="[1-8][0-9]{4}" title="10000 - 80000" /></td>
                </tr>
                <tr>
                    <th>Telefón:</th>
                    <td><input type="text" name="conPhone" value="${invoice.consumer.phone}" pattern="[[\+][1-9][0-9]{11}]?" title="telefon např.: +420123456789" /></td>
                </tr>
                <tr>
                    <th>E-mail:</th>
                    <td><input type="email" name="conMail" value="${invoice.consumer.mail}"/></td>
                </tr>
                <tr>
                    <th>IČO:</th>
                    <td><input type="text" name="conICO" value="${invoice.consumer.idNumber}"  pattern="[[1-9][0-9]{7}]?" title="IČO v rozsahu 10000000 - 99999999" /></td>
                </tr>
            </table><br />
                Položky: <span class="button"><a href="#items" onclick="addRow()">pridat polozku</a></span>
            <table id="items" style="margin:0px auto">
                <tr id="row1">
                    <th>Názov*:</th>
                    <td><input type="text" name="itemName1" value="${invoice.items[0].note}" required="required" title="název zboží" /></td>
                    <th>Cena*:</th>
                    <td><input type="text" name="itemPrice1" value="${invoice.items[0].priceForUnit}" required="required" pattern="[0-9]+|[0-9]+\.[0-9]+" title="např.: 1.0" /></td>
                    <th>Počet*:</th>
                    <td><input type="text" name="itemAmount1" value="${invoice.items[0].count}" required="required" pattern="[1-9][0-9]*" title="Množství zboží" /></td>
                </tr>
                <c:forEach items="${invoice.items}" begin="1" var="item" varStatus="loopStatus">
                    <tr id ="row${loopStatus.index+1}">
                        <th>Názov*:</th><td><input type="text" name="itemName${loopStatus.index+1}" value="${item.note}" required="required" title="název zboží" /></td>
                        <th>Cena*:</th><td><input type="text" name="itemPrice${loopStatus.index+1}"  value="${item.priceForUnit}" required="required" pattern="[0-9]+|[0-9]+\.[0-9]+" title="např.: 1.0" /></td>
                        <th>Počet*:</th><td><input type="text" name="itemAmount${loopStatus.index+1}"  value="${item.count}" required="required" pattern="[1-9][0-9]*" title="Množství zboží" /></td>               
                    </tr>
                </c:forEach>
            </table>
            <c:if test="${not empty error}">
                <p class="error">
                    <c:out escapeXml="false" value="${error}"/>
                </p>
            </c:if>
            <p>
                <input type="Submit" value="Upraviť faktúru" name="submit" />
                <span class="button"><a href="index.jsp">Zrušiť</a></span>
            </p>
        </form>
        </div>
    </body>
</html>

